/**
 * Created by Administrator on 2018/10/28.
 */
$(function () {
    var $account = $('#register-account');
    var $password = $('#register-password');
    var $passwordAgain = $('#register-passwordAgain');
    var $mobile = $('#register-mobile');
    var $getCodeBtn = $('#register-getCodeBtn');
    var $vCode = $('#register-vCode');
    var $registerSub = $('#register-sub');

    $getCodeBtn.on('click', function () {
        var mobile = $mobile.val();
        if (!mobile) {
            _alert('请输入手机号');
            return;
        }
        ajax({
            url: 'sms/sendSmsCode',
            data: {
                phone: mobile,
                type: 'register'
            },
            success: function (d) {
                _alert('发送成功');
            },
            fail: function () {
                _alert('发送验证码失败');
            }
        })
    });

    $registerSub.on('click', function () {

        if (!$account.val()) {
            _alert('请输入账号');
            return;
        }
        if (!$mobile.val()) {
            _alert('请输入手机号码');
            return;
        }

        if (!$vCode.val()) {
            _alert('请输入验证码');
            return;
        }

        if (!$password.val()) {
            _alert('请输入密码');
            return;
        }
        if (!$passwordAgain.val()) {
            _alert('请再次输入密码');
            return;
        }
        if ($password.val() != $passwordAgain.val()) {
            _alert('两次输入的密码不一致');
            return;
        }


        ajax({
            url: 'app/user/register',
            data: {
                phone: $mobile.val(),
                userName: $account.val(),
                smsCode: $vCode.val(),
                password: $password.val(),
                sex: parseInt($('input[type=radio]:checked').val())
            },
            success: function (d) {
                _alert('注册成功');
            },
            fail: function (d) {
                _alert(d.message.msg || '登录失败');
            }
        })
    });
});